<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:t="http://myfaces.apache.org/tomahawk"
	template="/pages/template/main-layout.xhtml">

	<ui:define name="content">
		<t:saveState value="#{evokQtnaireBean.qtnaire}" />
		<t:saveState value="#{evokQtnaireBean.parent}" />
		<t:saveState value="#{evokQtnaireBean.qtCategory}" />
		<t:saveState value="#{evokQtnaireBean.qtCategoryList}" />
		<t:saveState value="#{evokQtnaireBean.qt}" />
		<t:saveState value="#{evokQtnaireBean.qtList}" />
		<h:panelGrid border="0" columns="3">
			<p:commandButton value="#{msgs.button_add}"
				actionListener="#{evokQtnaireBean.add}"
				update=":mainform:qtnaireInfo,:messages,:mainform:categoryList,:mainform:qtList"
				icon="ui-icon-plus" style="top:0px;position:relative;" />

			<p:commandButton value="#{msgs.button_delete}"
				oncomplete="confirmDelete.show();" icon="ui-icon-close"
				style="position:relative" />
		</h:panelGrid>
		<br />
		<h:panelGrid columns="2" cellspacing="5"
			columnClasses="width30, width70" style="width:100%">
			<h:panelGrid border="0" id="qtnaireTree">
				<p:tree value="#{evokQtnaireBean.rootQtnaire}" var="node"
					selectionMode="single" style="background:none; width:100%;">
					<p:ajax event="select"
						update=":mainform:qtnaireInfo,:mainform:categoryList,:mainform:qtList"
						listener="#{evokQtnaireBean.onNodeSelect}" />
					<p:treeNode>
						<h:outputText value="#{node.code} - #{node.name}" styleClass="tree_font" />
					</p:treeNode>
				</p:tree>
			</h:panelGrid>
			<h:panelGroup>
				<p:panel id="qtnaireInfo">
					<h:inputHidden value="#{evokQtnaireBean.qtnaire.id}" />
					<h:inputHidden value="#{evokQtnaireBean.parent.id}" />

					<h:panelGrid columns="2" cellpadding="3" cellspacing="3"
						width="100%" columnClasses="width20,width80">
						<h:outputLabel for="qtnairename" value="#{msgs.default_name}" />
						<p:inputText id="qtnairename"
							value="#{evokQtnaireBean.qtnaire.name}" maxlength="255"
							style="width:90%" />
							
						<h:outputLabel for="qtnairecode" value="#{msgs.default_code}" />
						<p:inputText id="qtnairecode"
							value="#{evokQtnaireBean.qtnaire.code}" maxlength="20"
							style="width:90%" />	

						<h:outputLabel for="qtnairedesc" value="#{msgs.default_remark}" />
						<p:inputText id="qtnairedesc"
							value="#{evokQtnaireBean.qtnaire.remark}" maxlength="255"
							style="width:90%" />

						<h:outputLabel for="parent" value="#{msgs.qtnaire_parent}" />
						<h:outputText id="parent" value="#{evokQtnaireBean.parent.name}" />

						<h:outputLabel for="order" value="#{msgs.default_sort}" />
						<p:inputText id="order" value="#{evokQtnaireBean.qtnaire.sort}"
							style="width:90%">
							<f:validateLongRange minimum="0" maximum="100" />
						</p:inputText>
						
						<h:outputLabel for="page" value="STRANICA" />
						<p:inputText id="page"
							value="#{evokQtnaireBean.qtnaire.page}" maxlength="100"
							style="width:90%" />
							
						<h:outputLabel for="beanName" value="BEAN NAME" />
						<p:inputText id="beanName"
							value="#{evokQtnaireBean.qtnaire.beanName}" maxlength="100"
							style="width:90%" />	

						<f:facet name="footer">
							<h:panelGroup style="float:left">
								<p:commandButton value="#{msgs.button_submit}"
									icon="ui-icon-disk"
									update=":mainform:qtnaireInfo,:mainform:qtnaireTree,:messages"
									actionListener="#{evokQtnaireBean.submit}" />
							</h:panelGroup>
						</f:facet>
					</h:panelGrid>
				</p:panel>
				<br />
				<h:panelGrid width="100%">
					<p:toolbar>
						<p:toolbarGroup align="right">
							<p:commandLink title="#{msgs.button_add}"
								styleClass="ui-icon ui-icon-circle-plus" type="image"
								actionListener="#{evokQtnaireBean.addCategoryAction}"
								update=":mainform:categoryList,:mainform:qtList,:messages" />
						</p:toolbarGroup>
					</p:toolbar>
					<p:dataTable id="categoryList"
						value="#{evokQtnaireBean.categoryModel}" var="ct" emptyMessage=""
						selectionMode="single">
						<p:ajax event="rowEdit" update=":messages"
							listener="#{evokQtnaireBean.categoryEdit}" />
						<p:ajax event="rowSelect"
							listener="#{evokQtnaireBean.categorySelect}"
							update=":mainform:qtList" />
						<f:facet name="header">
							<h:outputText value="#{msgs.qtnaire_category_title}" />
						</f:facet>
						<p:column headerText="#{msgs.default_sort}">
							<p:cellEditor>
								<f:facet name="output">
									<h:outputText value="#{ct.sort}" />
								</f:facet>
								<f:facet name="input">
									<p:inputText value="#{ct.sort}" required="true"
										label="#{msgs.default_sort}" style="width:80%" />
								</f:facet>
							</p:cellEditor>
						</p:column>
						<p:column headerText="#{msgs.default_name}">
							<p:cellEditor>
								<f:facet name="output">
									<h:outputText value="#{ct.name}" />
								</f:facet>
								<f:facet name="input">
									<p:inputText value="#{ct.name}" style="width:80%"
										label="#{msgs.default_name}" required="true" />
								</f:facet>
							</p:cellEditor>
						</p:column>
						<p:column headerText="#{msgs.qtnaire_result}">
							<p:cellEditor>
								<f:facet name="output">
									<h:outputText value="#{ct.result.name}" />
								</f:facet>
								<f:facet name="input">
									<p:selectOneMenu value="#{ct.result}"
										converter="resultConverter">
										<f:selectItem itemLabel="" itemValue="" />
										<f:selectItems value="#{evokEnumBean.resultList}" var="rs"
											itemLabel="#{rs.name}" itemValue="#{rs}" />
									</p:selectOneMenu>
								</f:facet>
							</p:cellEditor>
						</p:column>
						<p:column headerText="#{msgs.table_column_operation}">
							<p:rowEditor />

							<p:commandLink oncomplete="confirmDeleteCategory.show()"
								styleClass="ui-icon ui-icon-trash" title="#{msgs.button_delete}"
								type="image">
								<f:setPropertyActionListener value="#{ct}"
									target="#{evokQtnaireBean.qtCategory}" />
							</p:commandLink>
						</p:column>
					</p:dataTable>
				</h:panelGrid>
				<br />
				<h:panelGrid width="100%">
					<p:toolbar>
						<p:toolbarGroup align="right">
							<p:commandLink title="#{msgs.button_add}"
								styleClass="ui-icon ui-icon-circle-plus" type="image"
								actionListener="#{evokQtnaireBean.addQtAction}"
								update=":mainform:qtList, :messages" />
						</p:toolbarGroup>
					</p:toolbar>
					<p:dataTable id="qtList" value="#{evokQtnaireBean.qtModel}"
						var="qt" emptyMessage="" selectionMode="single">
						<p:ajax event="rowEdit" update=":messages"
							listener="#{evokQtnaireBean.qtEdit}" />
						<p:ajax event="rowSelect" listener="#{evokQtnaireBean.qtSelect}"
							update=":messages" />
						<f:facet name="header">
							<h:outputText value="#{msgs.qtnaire_qt_title}" />
						</f:facet>
						<p:column headerText="#{msgs.default_sort}">
							<p:cellEditor>
								<f:facet name="output">
									<h:outputText value="#{qt.sort}" />
								</f:facet>
								<f:facet name="input">
									<p:inputText value="#{qt.sort}" required="true"
										label="#{msgs.default_sort}" style="width:80%" />
								</f:facet>
							</p:cellEditor>
						</p:column>
						<p:column headerText="#{msgs.default_name}">
							<p:cellEditor>
								<f:facet name="output">
									<h:outputText value="#{qt.name}" />
								</f:facet>
								<f:facet name="input">
									<p:inputText value="#{qt.name}" style="width:80%"
										label="#{msgs.default_name}" required="true" />
								</f:facet>
							</p:cellEditor>
						</p:column>
						<p:column headerText="SLIKA">
							<h:outputText value="#{qt.imgUrl}" />							
						</p:column>
						<p:column headerText="#{msgs.table_column_operation}">
							<p:rowEditor />

							<p:commandLink oncomplete="confirmDeleteQt.show()"
								styleClass="ui-icon ui-icon-trash" title="#{msgs.button_delete}"
								type="image">
								<f:setPropertyActionListener value="#{qt}"
									target="#{evokQtnaireBean.qt}" />
							</p:commandLink>
						</p:column>
					</p:dataTable>
					<br />
					<h:outputLabel for="fileupload" value="#{msgs.default_photo}" />
					<t:inputFileUpload id="fileupload" accept="image/*" size="50"
						value="#{evokQtnaireBean.upFile}" storage="file"
						maxlength="100000" />
					<p:commandButton value="#{msgs.button_submit}" icon="ui-icon-disk"
						update=":mainform:qtList,:messages" ajax="false"
						action="#{evokQtnaireBean.submitImage}" />
				</h:panelGrid>
			</h:panelGroup>
		</h:panelGrid>
	</ui:define>

	<ui:define name="dialog">
		<h:panelGrid>
			<p:confirmDialog message="#{msgs.info_sure_delete}" width="200"
				showEffect="explode" hideEffect="explode" header="POZOR"
				severity="alert" widgetVar="confirmDelete" modal="true">
				<p:commandButton value="DA"
					update=":mainform:qtnaireInfo,:messages,:mainform:categoryList,:mainform:qtList"
					actionListener="#{evokQtnaireBean.delete}"
					oncomplete="confirmDelete.hide()" />
				<p:commandButton value="NE" onclick="confirmDelete.hide()"
					type="button" />
			</p:confirmDialog>
			<p:confirmDialog message="#{msgs.info_sure_delete}" width="200"
				showEffect="explode" hideEffect="explode" header="POZOR"
				severity="alert" widgetVar="confirmDeleteCategory" modal="true">
				<p:commandButton value="DA"
					update=":mainform:categoryList,:mainform:qtList,:messages"
					actionListener="#{evokQtnaireBean.deleteCategoryAction}"
					oncomplete="confirmDeleteCategory.hide()" />
				<p:commandButton value="NE" onclick="confirmDeleteCategory.hide()"
					type="button" />
			</p:confirmDialog>
			<p:confirmDialog message="#{msgs.info_sure_delete}" width="200"
				showEffect="explode" hideEffect="explode" header="POZOR"
				severity="alert" widgetVar="confirmDeleteQt" modal="true">
				<p:commandButton value="DA" update=":mainform:qtList,:messages"
					actionListener="#{evokQtnaireBean.deleteQtAction}"
					oncomplete="confirmDeleteQt.hide()" />
				<p:commandButton value="NE" onclick="confirmDeleteQt.hide()"
					type="button" />
			</p:confirmDialog>
		</h:panelGrid>
	</ui:define>
</ui:composition>

